#/usr/bin/python3

from locust import HttpLocust, TaskSet, task
import random
import datetime

class WebsiteTasks(TaskSet):
    def on_start(self):
        response = self.client.get("/")
        self.csrftoken = response.cookies["csrfToken"]
        self.count = 1
    
    @task
    def test(self):
        self.client.get("/getQuestion?name=狂犬病")

    @task
    def guide(self):
        self.client.post("/room", {
          "chName": "前台"
        },
        headers={"x-csrf-token": self.csrftoken})

    @task
    def login(self):
        self.client.post("/login", {
            "email": "test@test.com",
            "password": "1234"
        },
        headers={"x-csrf-token": self.csrftoken})

    @task
    def register(self):
        self.count += 1
        random.seed(datetime.datetime.now().microsecond)
        self.client.post("/register", {
          "email": "test@3test.com" + str(self.count + random.random()),
          "password": "test",
          "name": "jyzh",
          "position": "前台",
        },
        headers={"x-csrf-token": self.csrftoken})


class WebsiteUser(HttpLocust):
    task_set = WebsiteTasks
    min_wait = 5000
    max_wait = 15000